package com.example.controller;

import com.example.common.response.Result;
import com.example.model.entity.Comment;
import com.example.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/comments")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping
    public Result<Comment> createComment(@RequestBody Comment comment,
                                       @RequestParam Long userId,
                                       @RequestParam Long postId) {
        return Result.success(commentService.createComment(comment, userId, postId));
    }

    @GetMapping("/post/{postId}")
    public Result<List<Comment>> getCommentsByPostId(@PathVariable Long postId) {
        return Result.success(commentService.findByPostId(postId));
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteComment(@PathVariable Long id) {
        commentService.deleteComment(id);
        return Result.success(null);
    }
} 